define(function(require, exports, module) {
    'use strict';
    
    var rk = require('rk');
    
    $.widget('rk.colleagueContentImpression', {
        _create:function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            //var temp = require("oa/tmpl/colleague/content/tpl_colleague_content_impression.tpl");
            //elem.html(temp);
            me._listeners();
        },
        _init:function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var temp = require("oa/tmpl/colleague/content/tpl_colleague_content_impression.tpl");
            rk.post("/json/oa_profile/impression.action",{u:opt.uid},function(json){
                var html = rk.templateText(temp,json);
                elem.html(html);
            });
        },
        _listeners:function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            elem.on("click", "[act='colleague_content_add_impress_button']", function(){
                var text = elem.find("[act='colleague_content_add_impress_text']").val();
                rk.post("/json/oa_profile-edit/impression-add.action",{u:opt.uid,content:text},function(json){
                    if(json.status == 0){
                        elem.colleagueContentImpression(opt);
                    }else if(json.status == 219003){
                        rk.noticeError(rk.i18n('COLLEAGUE_ONE_IMPRESSION_A_DAT_ERROR'));
                    }else if(json.status == 219002){
                        rk.noticeError(rk.i18n('COLLEAGUE_IMPRESSION_ON_MYSELF_ERROR'));
                    }else{
                        rk.noticeError(rk.i18n('COLLEAGUE_SYSTEM_ERROR'));
                    }
                });
            });
            elem.on("click", "[act='colleague_content_impression_share']", function(){
                var button = $(this);
                var imprId = button.attr("imprId");
                rk.post("/json/oa_profile-edit/impression-share.action",{u:opt.uid,impressionId:imprId},function(json){
                    if(json.status == 0){
                        elem.colleagueContentImpression(opt);
                    }else if(json.status == 219003){
                        rk.noticeError(rk.i18n('COLLEAGUE_ONE_IMPRESSION_A_DAT_ERROR'));
                    }else if(json.status == 219002){
                        rk.noticeError(rk.i18n('COLLEAGUE_IMPRESSION_ON_MYSELF_ERROR'));
                    }else{
                        rk.noticeError(rk.i18n('COLLEAGUE_SYSTEM_ERROR'));
                    }
                });
            });
            elem.on("click", "[act='colleague_content_impression_delete']", function(){
                var button = $(this);
                var imprId = button.attr("imprId");
                rk.confirm(rk.i18n('COLLEAGUE_CONFIRM_DELETE'), function () {
                    rk.post("/json/oa_profile-edit/impression-del.action",{impressionId:imprId},function(json){
                        if(json.status == 0){
                            elem.colleagueContentImpression(opt);
                        }else{
                            rk.noticeError(rk.i18n('COLLEAGUE_SYSTEM_ERROR'));
                        }
                    });
                }, function () {
                    //取消
                });
            });
        }
    });
});